package offer;

public class offer_0022 {
    public ListNode getKthFromEnd(ListNode head, int k) {
        if(head==null) return null;
        ListNode p=head;
        ListNode q=head;
        for(int i=0;i<k-1;++i){
            if(p!=null) p=p.next;
        }
        while(p!=null&&p.next!=null){
            p=p.next;
            q=q.next;
        }
        return q;
    }
}
